//index.js
//获取应用实例
const app = getApp()
const http = require('../../utils/http');
Page({
    data: {
        mobile: '',
        isToken: false,
        iv: '',
        encryptedData: '',
        isRuleTrue: true,
    },
    //事件处理函数

    onLoad: function () {

    },

    getPhoneNumber: function (e) {
        if (e.detail.iv) {
            const body = {
                sessionKey: app._sessionKey,
                encryptedData: e.detail.encryptedData,
                ivStr: e.detail.iv,
                openid: app._openid,
            }
            http._objPost("/mini/savePhone", body).then(res => {
                if (res.code == 200) {
                    wx.navigateTo({
                        url: '../publicToken/publicToken?openid=' + app._openid
                    })
                } else {
                    wx.showToast({
                        title: res.message,
                        icon: 'none',
                        duration: 2000
                    });
                    setTimeout(function () {
                        wx.hideToast()
                    }, 2000)
                }
            })

        } else {
            wx.showToast({
                title: "为了您更好的体验,请先同意授权",
                icon: 'none',
                duration: 2000
            });
        }
    },
})
